package com.easy;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Lxk on 2020/2/12.
 */
public class Solution566 {

    public int[][] matrixReshape(int[][] nums, int r, int c) {
        int row = nums.length, col = nums[0].length;
        if (r * c != row * col) {
            return nums;
        }
        List<Integer> numList = new ArrayList<>();
        for (int i = 0; i < row; i++) {
            for (int k = 0; k < col; k++) {
                numList.add(nums[i][k]);
            }
        }
        int[][] matrix = new int[r][c];
        for (int i = 0; i < r; i++) {
            for (int k = 0; k < c; k++) {
                matrix[i][k] = numList.get(i * c + k);
            }
        }
        return matrix;
    }

    public static void main(String[] args) {
        int[][] matrix = {{1, 2}, {3, 4}};
        Solution566 solution566 = new Solution566();
        int[][] res = solution566.matrixReshape(matrix, 4, 1);
        System.out.println(res);
    }

}
